﻿using System;
using System.Collections.Generic;
using System.Linq;
using Metro.Kashikoi.Common;
using Metro.Kashikoi.Service.Common.Entity;

namespace Metro.Kashikoi.Service.Test.Common
{
    /// <summary>
    /// 
    /// </summary>
    public class MockContext : Disposable, IUnitOfWork
    {
        List<object> set = new List<object>();

        public MockContext()
        {
            this.Saved = false;
        }

        public bool Saved { get; set; }

        #region IUnitOfWork Members

        public IList<TEntity> Set<TEntity>() where TEntity : class
        {
            return set.OfType<TEntity>().ToList();
        }

        public int SaveChanges()
        {
            this.Saved = true;
            return 1;
        }

        public void Delete<TEntity>(TEntity entity) where TEntity : class
        {
            Set<TEntity>().Remove(entity);
        }

        public void Add<TEntity>(TEntity entity) where TEntity : class
        {
            set.Add(entity);
        }

        public void Remove<TEntity>(TEntity entity) where TEntity : class
        {
            Set<TEntity>().Remove(entity);
        }

        public void Attach<TEntity>(TEntity entity) where TEntity : class
        {
            // Nothing to do.
        }

        public System.Linq.IQueryable<TEntity> GetQuery<TEntity>() where TEntity : class
        {
            return Set<TEntity>().AsQueryable();
        }

        #endregion

        #region Disposable Members

        public override void Disposing()
        {
            // Nothing to do.
        }

        #endregion

    }
}
